<%--
  Created by IntelliJ IDEA.
  User: 林不清
  Date: 2020/12/14
  Time: 10:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="entity.User" %>
<%@ page import="org.omg.PortableInterceptor.USER_EXCEPTION" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改个人信息</title>
    <script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>
    <link rel="stylesheet" href="css/index.css">
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" event="onload">
        function onchangeFunction() {
            $.get("/FinalWork/showPhotoAjax", {"uFace":$("#change_img").val()}, function (data, status) {
                console.log($("#change_img").val())
                $("#preview_div").html(data);
            })
        }
    </script>
</head>
<%
    User user = (User) session.getAttribute("user");
%>

<body>
<%request.setCharacterEncoding("utf-8");%>
<%--修改信息--%>
<div class="righter" style="border: white 5px solid">
    <a href="#" name="change_info"></a>
    <!--            修改信息-->
    <form action="change.jhtml?method=edit&id=<%=user.getId()%>" method="post" name="ChangeInfoForm">
        <div class="change_info">
            <div class="info">
                <span class="title">账号信息</span>
                <div class="line"></div>
                <div class="item">
                    <span class="item_key">ID </span>
                    <%--                    ID不可更改--%>
                    <div class="item_val"><%=user.getId()%></div>
                </div>
                <div class="item">
                    <span class="item_key">用户名 </span>
                    <input type="text" class="input_val" name="uname" value="<%=user.getName()%>">
                </div>
                <div class="item">
                    <span class="item_key">密码 </span>
                    <input type="password" class="input_val" name="password" value="<%=user.getPassword()%>">
                </div>
                <div class="item">
                    <span class="item_key">手机号 </span>
                    <input type="text" class="input_val" name="phone" placeholder="<%=user.getPhone()%>">
                </div>
                <div class="item">
                    <span class="item_key">姓名 </span>
                    <%
                        String real_name =user.getReal_name();
                        if(real_name==null||real_name.equals("")){
                            real_name="未填写";
                        }
                    %>
                    <input type="text" class="input_val" name="real_name" value="<%=real_name%>">
                </div>
                <div class="item">
                    <span class="item_key">性别 </span>
                    <%
                        String sex;
                        if (user.getSex()==true){
                            sex = "男";
                        }else if(user.getSex()==false){
                            sex="女";
                        }else{
                            sex = "未填写";
                        }
                    %>
                    <input type="text" class="input_val" name="sex" value="<%=sex%>">
                </div>
                <div class="item">
                    <span class="item_key">Email </span>
                    <%
                        String email=user.getEmail();
                        if (email==null||email.equals("")){
                            email="未填写";
                        }
                    %>
                    <input type="text" class="input_val" name="email" value="<%=email%>">
                </div>
            </div>
            <div class="info">
                <span class="title">学历简介</span>
                <div class="line"></div>
                <div class="item">
                    <span class="item_key">学校 </span>
                    <input type="text" class="input_val" name="school" value="<%=user.getSchool()%>">
                </div>
                <div class="item">
                    <span class="item_key">年级 </span>
                    <input type="text" class="input_val" name="grade" value="<%=user.getGrade()%>">
                </div>
            </div>
            <div class="info">
                <span class="title">我的头像</span>
                <div class="line"></div>
                <div class="face" id="preview_div" style="width: 70px;height: 70px;border: lightcoral 1px solid;margin-left: 30px;margin-top: 15px">
                    <img id="preview" src="img/head/<%=user.getImg_path()%>" style="width: 100%;height: 100%;">
                </div>
                <select id="change_img" onchange="onchangeFunction()" name="face" >
                    <%
                        String[] photo = new String[17];
                        photo[0]="default_photo.gif";
                        for (int i = 1; i <= 16; ++i) {
                            photo[i] = i + ".gif";
//                                System.out.println(photo[i]+" "+user.getImg_path()+" "+photo[i-1]);
//                            System.out.println(user.getImg_path().equals(photo[i-1]));
                            if (photo[i-1].equals(user.getImg_path()))
                            {
                    %>
                    <option value="<%=photo[i-1]%>" selected="selected">
                        <%=photo[i-1]%>
                    </option>

                    <%} else {%>
                    <option value="<%=photo[i-1]%>">
                        <%=photo[i-1]%>
                    </option>

                    <%}
                    }%>
                </select>

                <input type="submit" value="提交">
            </div>
        </div>

    </form>
</div>
</body>
</html>
